<style>
    .image {
        width: 60px;
        height: 60px;
    }
</style>
<div class="layuimini-container">
    <form id="app-form" class="layui-form layuimini-form">
        <div class="layui-form-item" id="product">
            <label class="layui-form-label">spu商品</label>
            <div id="images">
                <img src="{$row.goods_image}" class='image' />
                <img src="__STATIC__/admin/images/+.jpg" data-url="selectGoods" data-method="offset"
                     style="border: 1px dashed black;" class="image">
            </div>
            <input type="hidden" id="goods_id" name="goods_id" value="{$row.goods_id|default=''}">
        </div>
        <div class="layui-form-item" id="goodsSku">
            <label class="layui-form-label">sku商品</label>
            <div id="sku_images">
                <img src="{$image}" class='image' />
                <img src="__STATIC__/admin/images/+.jpg" data-method="offset" style="border: 1px dashed black;" class="image">
            </div>
            <input type="hidden" id="sku_id" name="sku_id" value="{$row.sku_id|default=''}">
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">砍价活动名称</label>
            <div class="layui-input-block">
                <input type="text" name="title" class="layui-input"  placeholder="请输入砍价活动名称" value="{$row.title|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">砍价活动简介</label>
            <div class="layui-input-block">
                <input type="text" name="info" class="layui-input"  placeholder="请输入砍价活动简介" value="{$row.info|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">砍价活动图片</label>
            <div class="layui-input-block layuimini-upload">
                <input name="image" class="layui-input layui-col-xs6"   placeholder="请上传砍价活动图片" value="{$row.image|default=''}">
                <div class="layuimini-upload-btn">
                    <span><a class="layui-btn" data-upload="image" data-upload-number="one" data-upload-exts="png|jpg|ico|jpeg" data-upload-icon="image"><i class="fa fa-upload"></i> 上传</a></span>
                    <span><a class="layui-btn layui-btn-normal" id="select_image" data-upload-select="image" data-upload-number="one" data-upload-mimetype="image/*"><i class="fa fa-list"></i> 选择</a></span>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">库存</label>
            <div class="layui-input-block">
                <input type="text" name="stock" class="layui-input"  placeholder="请输入库存" value="{$row.stock|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">活动开启时间</label>
            <div class="layui-input-block">
                <input type="datetime-local" name="start_time" class="layui-input"  placeholder="请输入活动开启时间" value="{$row.start_time|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">活动结束时间</label>
            <div class="layui-input-block">
                <input type="datetime-local" name="end_time" class="layui-input"  placeholder="请输入活动结束时间" value="{$row.end_time|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品价格</label>
            <div class="layui-input-block">
                <input type="text" name="price" class="layui-input"  placeholder="请输入商品价格" value="{$row.price|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">购买数量</label>
            <div class="layui-input-block">
                <input type="text" name="num" class="layui-input"  placeholder="请输入购买数量" value="{$row.num|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">砍价目标金额</label>
            <div class="layui-input-block">
                <input type="text" name="bargain_price" class="layui-input"  placeholder="请输入砍价目标金额" value="{$row.bargain_price|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">每次砍的最大金额</label>
            <div class="layui-input-block">
                <input type="text" name="bargain_max_price" class="layui-input"  placeholder="请输入每次砍的最大金额" value="{$row.bargain_max_price|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">每次砍的最低金额</label>
            <div class="layui-input-block">
                <input type="text" name="bargain_min_price" class="layui-input"  placeholder="请输入每次砍的最低金额" value="{$row.bargain_min_price|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">砍价总人数</label>
            <div class="layui-input-block">
                <input type="text" name="bargain_num" class="layui-input"  placeholder="请输入砍价总人数" value="{$row.bargain_num|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">返回积分</label>
            <div class="layui-input-block">
                <input type="text" name="give_intergal" class="layui-input"  placeholder="请输入返回积分" value="{$row.give_intergal|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="text" name="sort" class="layui-input"  placeholder="请输入排序" value="{$row.sort|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否包邮</label>
            <div class="layui-input-block">
                <input type="text" name="is_postage" class="layui-input"  placeholder="请输入是否包邮" value="{$row.is_postage|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮费</label>
            <div class="layui-input-block">
                <input type="text" name="postage" class="layui-input"  placeholder="请输入邮费" value="{$row.postage|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">运费模版</label>
            <div class="layui-input-block">
                <input type="text" name="temp_id" class="layui-input"  placeholder="请输入运费模版" value="{$row.temp_id|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">分享次数</label>
            <div class="layui-input-block">
                <input type="text" name="share" class="layui-input"  placeholder="请输入分享次数" value="{$row.share|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">砍价规则</label>
            <div class="layui-input-block">
                <input type="text" name="rule" class="layui-input"  placeholder="请输入砍价规则" value="{$row.rule|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            {if($row.status)}
            <input type="checkbox" checked="" value="1" name="status" lay-skin="switch" lay-filter="switchTest" lay-text="开启|关闭">
            {else /}
            <input type="checkbox" value="1" name="is_give_subscribe" lay-skin="switch" lay-filter="switchTest" lay-text="开启|关闭">
            {/if}
        </div>
        <div class="hr-line"></div>
        <div class="layui-form-item text-center">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit>确认</button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">重置</button>
        </div>

    </form>
</div>
<script>
    layui.use(['jquery', 'form', 'upload', 'element', 'layer'], function () {
        var $ = layui.jquery;
        layer = layui.layer;

        var active = {
            offset: function (othis, url) {
                var type = othis.data('type')
                let goods_id = $("#goods_id").val();
                if (url == undefined) {
                    return false;
                }
                //添加商品
                layer.open({
                    type: 2
                    , area: ['800px', '600px']
                    , offset: type //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                    , id: 'layerDemo' + type //防止重复弹出
                    , content: "{:url('store.goods/" + url + "')}?goods_id=" + goods_id
                    , btnAlign: 'c' //按钮居中
                    , shade: 0 //不显示遮罩
                    , yes: function () {
                        layer.closeAll();
                    }
                    , end: function (e) {
                        let sku_id = $("#sku_id").val();
                        console.log(sku_id);
                        if (sku_id !== '') {
                            $.ajax({
                                url: "{:url('store.goods/getSkuDetail')}",
                                data: {skuId: sku_id},
                                type: "get",
                                dataType: "json",
                                success: (res) => {
                                    console.log(res);
                                    $("#sku_stock").val(res.sku_stock);
                                    $("#sku_price").val(res.sku_price);
                                }
                            })
                        }

                    }
                });
            }
        }

        $('.image').on('click', function () {
            var othis = $(this), method = othis.data('method'), url = othis.data('url');
            active[method] ? active[method].call(this, othis, url) : '';
        });

    })

</script>